#coding: utf-8
'''
simple log class
'''

import os, sys
import time
import logging, logging.config

STANDART_FORMAT = '[%(asctime)s][%(filename)s:%(lineno)d][%(levelname)s][%(message)s]'
SIMPLE_FORMAT   = '[%(levelname)s][%asctime)s][%(message)s]'
LOGFILENAME     = time.strftime("%Y-%m-%d-%H.log", time.localtime())
LOGFILEPATH     = os.path.dirname(os.path.abspath(__file__))

if not os.path.isdir(LOGFILEPATH):
    os.mkdir(LOGFILEPATH)

LOGGING_DIC = {
    'version' : 1,
    'disable_existing_loggers': False,
    'formatters': {
        'standard': {
            'format': STANDART_FORMAT
        },
        'simple': {
            'format': SIMPLE_FORMAT
        }
    },
    'filters':{},
    'handlers':{
        #print to console
        'console':{
            'level': "DEBUG",
            'class': "logging.StreamHandler",
            'formatter': "simple"
        },
        'default':{
            'level': "DEBUG",
            'class': "logging.handlers.RotatingFileHandler", #save to file
            'formatter': "standard",
            'filename': os.path.join(LOGFILEPATH, LOGFILENAME),
            'maxBytes': 1024*1024*2, #2MByte
            'backupCount': 5,
            'encoding': 'utf-8'
        },
    },
    'loggers': {
        '': {
            'handlers':['default', 'console'],
            'level': 'DEBUG',
            'propgate': True,
        },
    },
}

logging.config.dictConfig(LOGGING_DIC)

def GetMyLogger(name):
    return logging.getLogger(name)

if __name__ == "__main__":
    log = GetMyLogger("river")
    log.debug("debug hello world!")
    log.info("info test")
